package learningThread.syn.synchronizedMethodLockObj.communicate.testEarly;

public class NotifyEarly {

    private String lock = new String("");

    private Runnable runnableA = new Runnable() {
        @Override
        public void run() {
            try {
                synchronized (lock){
                    System.out.println("begin waite");
                    lock.wait();
                    System.out.println("end waite");
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    };

    private Runnable runnableB = new Runnable() {
        @Override
        public void run() {
            synchronized (lock){
                System.out.println("begin notify");
                lock.notify();
                System.out.println("end notify");
            }
        }
    };

    //若threadB先于threadA执行完成，那么
    public static void main(String[] args) {
//        NotifyEarly notifyEarly = new NotifyEarly();
//        Thread threadA = new Thread(notifyEarly.runnableA);
//        Thread threadB = new Thread(notifyEarly.runnableB);
//        threadA.start();
//        threadB.start();

        NotifyEarly notifyEarly = new NotifyEarly();
        Thread threadB = new Thread(notifyEarly.runnableB);
        threadB.start();
        Thread threadA = new Thread(notifyEarly.runnableA);
        threadA.start();

    }
}
